﻿using InnoWeb.CEND.BL.Infrastructure;
using InnoWeb.CEND.Core.Model.User;
using InnoWeb.CEND.Data;
using InnoWeb.CEND.Data.Infrastructure;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace InnoWeb.CEND.BL.Service
{
    public class UserService:IService<User>
    {
        private readonly GenericRepository<User> _userRepository;
        private readonly IUnitOfWork _unitOfWork;


        public UserService(IUnitOfWork unitOfWork, GenericRepository<User> userRepo)
        {
            this._unitOfWork = unitOfWork;
            this._userRepository = userRepo;
        }

        public IQueryable<User> GetAllElements()
        {
            return _userRepository.GetAll();
        }

        public User GetElementById(int id)
        {
            return _userRepository.GetById(id);
        }

        public void CreateElement(User entity)
        {
            _userRepository.Insert(entity);
        }

        public void UpdateElement(User entity)
        {
            _userRepository.Update(entity);
        }

        public void DeleteElement(int id)
        {
            var item = _userRepository.GetById(id);
            item.IsDeleted = true;
        }

        public void SaveChanges()
        {
            _unitOfWork.SaveChanges();
        }
    }
}
